#ifndef V2_NIM_UTILITIES_H
#define V2_NIM_UTILITIES_H
#include "v2_nim_def_callback.hpp"
namespace v2 {
/// @brief IM 消息创建器
class V2NIMMessageCreator {
public:
    /// @brief 创建文本消息
    /// @param text 文本内容
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto textMessage = V2NIMMessageCreator::createTextMessage("hello world");
    /// if(!textMessage) {
    ///     // create text message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createTextMessage(nstd::string text);

    /// @brief 创建图片消息
    /// @param imagePath 图片路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @param width 图片宽度
    /// @param height 图片高度
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto imageMessage = V2NIMMessageCreator::createImageMessage("imagePath", "imageName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100,
    /// 100); if(!imageMessage) {
    ///     // create image message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createImageMessage(nstd::string imagePath,
        nstd::string name,
        nstd::string sceneName,
        uint32_t width,
        uint32_t height);

    /// @brief 创建音频消息
    /// @param audioPath 音频路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @param duration 音频时长
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto audioMessage = V2NIMMessageCreator::createAudioMessage("audioPath", "audioName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100);
    /// if(!audioMessage) {
    ///     // create audio message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration);

    /// @brief 创建视频消息
    /// @param videoPath 视频路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @param duration 视频时长
    /// @param width 视频宽度
    /// @param height 视频高度
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto videoMessage = V2NIMMessageCreator::createVideoMessage("videoPath", "videoName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100, 100, 100);
    /// if (!videoMessage) {
    ///     // create video message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createVideoMessage(nstd::string videoPath,
        nstd::string name,
        nstd::string sceneName,
        uint32_t duration,
        uint32_t width,
        uint32_t height);

    /// @brief 创建文件消息
    /// @param filePath 文件路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto fileMessage = V2NIMMessageCreator::createFileMessage("filePath", "fileName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM);
    /// if(!fileMessage) {
    ///     // create file message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName);

    /// @brief 创建位置消息
    /// @param latitude 纬度
    /// @param longitude 经度
    /// @param address 详细位置信息
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto locationMessage = V2NIMMessageCreator::createLocationMessage(100, 100, "address");
    /// if(!locationMessage) {
    ///     // create location message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createLocationMessage(double latitude, double longitude, nstd::string address);

    /// @brief 创建自定义消息
    /// @param text 文本内容
    /// @param attachment 附件
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto customMessage = V2NIMMessageCreator::createCustomMessage("text", R"({"key": "value"})");
    /// if(!customMessage) {
    ///     // create custom message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createCustomMessage(nstd::string text, nstd::string rawAttachment);

    /// @brief 创建提示消息
    /// @param text 文本内容
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto tipMessage = V2NIMMessageCreator::createTipsMessage("text");
    /// if(!tipMessage) {
    ///     // create tip message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createTipsMessage(nstd::string text);

    /// @brief 创建转发消息
    /// @param message 原消息
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto forwardMessage = V2NIMMessageCreator::createForwardMessage(message);
    /// if(!forwardMessage) {
    ///     // create forward message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createForwardMessage(V2NIMMessage message);

    /// @brief 构造话单消息
    /// @param type 话单类型，业务自定义，内容不校验
    /// @param channelId 话单频道 ID，内容不校验
    /// @param status 通话状态，业务自定义状态，内容不校验
    /// @param durations 通话成员时长列表，内容不校验
    /// @param text 话单描述
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto callMessage = V2NIMMessageCreator::createCallMessage(1, "channelId", 1, {{"account1", 100}, {"account2", 200}}, "text");
    /// if(!callMessage) {
    ///     // create call message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMMessage> createCallMessage(int32_t type,
        const nstd::string& channelId,
        int32_t status,
        const nstd::vector<V2NIMMessageCallDuration>& durations,
        const nstd::string& text);
};

class V2NIMMessageConverter {
public:
    /// @brief 将 V2NIMMessage 序列化为字符串
    /// @param message 消息体 {@link V2NIMMessage}
    /// @return nstd::string 序列化后的字符串
    static nstd::optional<nstd::string> messageSerialization(const V2NIMMessage& message);

    /// @brief 将字符串反序列化为 V2NIMMessage
    /// @param messageString 序列化后的字符串
    /// @return V2NIMMessage 反序列化后的消息体
    static nstd::optional<V2NIMMessage> messageDeserialization(const nstd::string& messageString);
};

/// @brief 聊天室消息创建器
class V2NIMChatroomMessageCreator {
public:
    /// @brief 创建文本消息
    /// @param text 文本内容
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto textMessage = V2NIMChatroomMessageCreator::createTextMessage("hello world");
    /// if(!textMessage) {
    ///     // create text message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createTextMessage(nstd::string text);

    /// @brief 创建图片消息
    /// @param imagePath 图片路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @param width 图片宽度
    /// @param height 图片高度
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto imageMessage = V2NIMChatroomMessageCreator::createImageMessage("imagePath", "imageName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100,
    /// 100); if(!imageMessage) {
    ///     // create image message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createImageMessage(nstd::string imagePath,
        nstd::string name,
        nstd::string sceneName,
        uint32_t width,
        uint32_t height);

    /// @brief 创建音频消息
    /// @param audioPath 音频路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @param duration 音频时长
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto audioMessage = V2NIMChatroomMessageCreator::createAudioMessage("audioPath", "audioName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100);
    /// if(!audioMessage) {
    ///     // create audio message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createAudioMessage(nstd::string audioPath,
        nstd::string name,
        nstd::string sceneName,
        uint32_t duration);

    /// @brief 创建视频消息
    /// @param videoPath 视频路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @param duration 视频时长
    /// @param width 视频宽度
    /// @param height 视频高度
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto videoMessage = V2NIMChatroomMessageCreator::createVideoMessage("videoPath", "videoName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100, 100,
    /// 100); if (!videoMessage) {
    ///     // create video message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createVideoMessage(nstd::string videoPath,
        nstd::string name,
        nstd::string sceneName,
        uint32_t duration,
        uint32_t width,
        uint32_t height);

    /// @brief 创建文件消息
    /// @param filePath 文件路径
    /// @param name 文件显示名称, 为空则使用文件名
    /// @param sceneName 文件存储场景
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto fileMessage = V2NIMChatroomMessageCreator::createFileMessage("filePath", "fileName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM);
    /// if(!fileMessage) {
    ///     // create file message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName);

    /// @brief 创建位置消息
    /// @param latitude 纬度
    /// @param longitude 经度
    /// @param address 详细位置信息
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto locationMessage = V2NIMChatroomMessageCreator::createLocationMessage(100, 100, "address");
    /// if(!locationMessage) {
    ///     // create location message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createLocationMessage(double latitude, double longitude, nstd::string address);

    /// @brief 创建自定义消息
    /// @param attachment 附件
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto customMessage = V2NIMChatroomMessageCreator::createCustomMessage(R"({"key": "value"})");
    /// if(!customMessage) {
    ///     // create custom message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createCustomMessage(nstd::string rawAttachment);

    /// @brief 创建提示消息
    /// @param text 文本内容
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto tipMessage = V2NIMChatroomMessageCreator::createTipsMessage("text");
    /// if(!tipMessage) {
    ///     // create tip message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createTipsMessage(nstd::string text);

    /// @brief 创建转发消息
    /// @param message 原消息
    /// @return nstd::optional<V2NIMChatroomMessage>
    /// @par 示例代码
    /// @code
    /// auto forwardMessage = V2NIMChatroomMessageCreator::createForwardMessage(message);
    /// if(!forwardMessage) {
    ///     // create forward message failed
    /// }
    /// @endcode
    static nstd::optional<V2NIMChatroomMessage> createForwardMessage(V2NIMChatroomMessage message);
};

/// @brief 会话ID工具
class V2NIMConversationIdUtil {
public:
    /// @brief 获取点对点会话ID
    /// @param accountId 账号ID
    /// @return nstd::string
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::p2pConversationId("target_account_id");
    /// @endcode
    static nstd::string p2pConversationId(const nstd::string& accountId);

    /// @brief 获取群组会话ID
    /// @param teamId 群组ID
    /// @return nstd::string
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::teamConversationId("team_id");
    /// @endcode
    static nstd::string teamConversationId(const nstd::string& teamId);

    /// @brief 获取超级群会话ID
    /// @param superTeamId 超级群ID
    /// @return nstd::string
    /// @par 示例代码
    /// @code
    /// auto conversationId = V2NIMConversationIdUtil::superTeamConversationId("super_team_id");
    /// @endcode
    static nstd::string superTeamConversationId(const nstd::string& superTeamId);

    /// @brief 获取会话ID对应的会话类型
    /// @param conversationId 会话ID
    /// @return V2NIMConversationType
    /// @par 示例代码
    /// @code
    /// auto conversationType = V2NIMConversationIdUtil::parseConversationType("conversation_id");
    /// @endcode
    static V2NIMConversationType parseConversationType(const nstd::string& conversationId);

    /// @brief 获取会话ID对应的目标ID
    /// @param conversationId 会话ID
    /// @return nstd::string
    /// @par 示例代码
    /// @code
    /// auto targetId = V2NIMConversationIdUtil::parseConversationTargetId("conversation_id");
    /// @endcode
    static nstd::string parseConversationTargetId(const nstd::string& conversationId);
};

/// @brief 本地反垃圾工具
class V2NIMClientAntispamUtil {
public:
    /// @brief 文本本地反垃圾
    /// @param text 需要本地反垃圾check的文本
    /// @param replace 敏感内容替换词
    /// @return nstd::optional<V2NIMMessage>
    /// @par 示例代码
    /// @code
    /// auto result = V2NIMClientAntispamUtil::checkTextAntispam("spam text", "*");
    /// @endcode
    static V2NIMClientAntispamResult checkTextAntispam(nstd::string text, nstd::string replace);
};

class V2NIMStorageUtil {
public:
    /// @brief 获取图片缩略图
    /// @param url 图片源地址
    /// @param thumbSize 缩略图尺寸，单位像素
    /// @return nstd::string
    /// @par 示例代码
    /// @code
    /// auto thumbURL= V2NIMStorageUtil::imageThumbUrl("image_url", 100);
    /// @endcode
    static nstd::string imageThumbUrl(const nstd::string& url, int32_t thumbSize);

    /// @brief 获取视频封面
    /// @param url 视频源地址
    /// @param offset 视频封面偏移时间，单位秒
    /// @param thumbSize 封面尺寸，单位像素
    /// @param type 封面类型，如 png，jpeg
    /// @return nstd::string
    /// @par 示例代码
    /// @code
    /// auto coverURL = V2NIMStorageUtil::videoCoverUrl("video_url", 0, 150, "png");
    /// @endcode
    static nstd::string videoCoverUrl(const nstd::string& url, int32_t offset, int32_t thumbSize, const nstd::string& type);
};

}  // namespace v2

#endif
